/**
 * Copyright (C) 2010 Sergey Grigoriev <s.a.grigoriev@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.gmf.core

import org.testng.annotations.Test
import org.apache.maven.plugin.logging.Log
import org.easymock.EasyMock
import org.testng.Assert


class OSCommandTest {

  @Test
  public void addOptions() {

    OSCommand command = new OSCommand("mxmlc", new File("."))
    command << ["-compiler.source-path=": "folder1"]

    Assert.assertEquals(
            ["mxmlc", '-compiler.source-path=folder1'],
            command.processOptions()
    )
  }

  @Test
  public void addArguments() {
    OSCommand command = new OSCommand("compc", new File("."))
    command << ['arg1', 'arg2']
    Assert.assertEquals(
            ['compc', 'arg1', 'arg2'],
            command.processOptions()
    )

    command << 'arg3'
    Assert.assertEquals(
            ['compc', 'arg1', 'arg2', 'arg3'],
            command.processOptions()
    )
  }

  @Test
  public void orderOfArguments() {
    OSCommand command = new OSCommand("compc", new File("."))
    command << ['arg1', '-arg2']
    Assert.assertEquals(
            ['compc', '-arg2', 'arg1'],
            command.processOptions()
    )

    command << 'arg3'
    Assert.assertEquals(
            ['compc', '-arg2', 'arg1', 'arg3'],
            command.processOptions()
    )
  }

  @Test
  public void mergeOptions() {
    OSCommand command = new OSCommand("compc", new File("."))
    command << ["-compiler.source-path=": "folder1"]
    command << ["-compiler.source-path=": "folder2"]
    Assert.assertEquals(
            ['compc', '-compiler.source-path=folder1', '-compiler.source-path=folder2'], command.processOptions()
    )
  }

  @Test
  public void concurrentModification() {
    OSCommand cmd = new OSCommand("compc", new File("."))
    cmd << [
            '-compiler.source-path=': '/home/sgr/Work/gmf/examples/mxmlc/src/main/flex',
            '-output=': '/home/sgr/Work/gmf/examples/mxmlc/target/mxmlc-0.1.swf'
    ]

    cmd << ['-compiler.source-path=': '/home/sgr/Work/gmf/examples/mxmlc/src/locales/flex/{locale}']
  }

  /*
  @Test
  public void differentOptionsSet() {
    OSCommand cmd = new OSCommand("mxmlc", new File("."))
    cmd << ['-compiler.source-path=':['/home/sgr/Work/gmf/examples/framework-rsl/src/main/flex','/home/sgr/Work/gmf/examples/framework-rsl/src/test/flex']]
    cmd << ['-output=':'/home/sgr/Work/gmf/examples/framework-rsl/target/test-classes/TestRunner.swf']
    cmd << ['-compiler.debug',  '-compiler.headless-server']
    cmd << ['-compiler.library-path=':'.']
       /opt/flex/flex_sdk_4/bin/mxmlc -compiler.source-path=/home/sgr/Work/gmf/examples/framework-rsl/src/main/flex,/home/sgr/Work/gmf/examples/framework-rsl/src/test/flex -output=/home/sgr/Work/gmf/examples/framework-rsl/target/test-classes/TestRunner.swf -compiler.debug -compiler.library-path+=/home/sgr/Work/gmf/examples/examples/../lib/flexunit -compiler.headless-server -compiler.library-path= /home/sgr/Work/gmf/examples/framework-rsl/src/test/flex/net/gmf/examples/frameworkRsl/TestRunner.mxml .
11084 [main] INFO  OSCommand  - stdout:   Loading configuration file /opt/flex/flex_sdk_4/frameworks/flex-config.xml
  }
  */
}
